﻿using Net8.Project.Common.Extensions;
using Net8.Project.Data.UnitOfWorks;
using Net8.Project.Model.Entity;
using SqlSugar;

namespace Net8.Project.Data.Repository
{
    public class UserRepository(IUnitOfWorkManage unitOfWorkManage) : BaseRepository<User>(unitOfWorkManage), IUserRepository
    {
        public async Task<User> GetUserAsync(int id)
        {
            await Task.CompletedTask; // 模拟异步操作
            var dataJson = "{\"Id\":" + id + ",\"UserName\":\"小明\",\"UserPwd\":\"321654987\"}"; // 示例数据
            return dataJson.ToObject<User>() ?? new User();
        }

        public async Task<List<RoleModulePermission>> RoleModuleMaps()
        {
            return await QueryMuch<RoleModulePermission, Modules, Role, RoleModulePermission>(
                (rmp, m, r) => new object[] {
                    JoinType.Left, rmp.ModuleId == m.Id,
                    JoinType.Left,  rmp.RoleId == r.Id
                },

                (rmp, m, r) => new RoleModulePermission()
                {
                    Role = r,
                    Module = m,
                    IsDeleted = rmp.IsDeleted
                },

                (rmp, m, r) => rmp.IsDeleted == false && m.IsDeleted == false && r.IsDeleted == false
                );
        }
    }
}
